package org.ls.petclinic.untils;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description
 * @Author 浪矢先生
 * @Create 2022-05-31 20:21
 */
public  class ResultJson {
    /**
     * 成功?
     */
        private Boolean success;
    /**
     * 状态码
     */
        private String code;
    /**
     * 消息
     */
        private String message;
    /**
     * 数据
     */
        private Map<String, Object> data = new HashMap<String, Object>();

        private ResultJson() {
        }

    public ResultJson(Boolean success, String code, String message, Map<String, Object> data) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static ResultJson ok() {
            ResultJson r = new ResultJson();
            r.setSuccess(true);
            r.setCode("200");
            r.setMessage("成功");
            return r;
        }

        public static ResultJson error() {
            ResultJson r = new ResultJson();
            r.setSuccess(false);
            r.setCode("500");
            r.setMessage("失败");
            return r;
        }

        public ResultJson success(Boolean success) {
            this.setSuccess(success);
            return this;
        }

        public ResultJson message(String message) {
            this.setMessage(message);
            return this;
        }

        public ResultJson code(String code) {
            this.setCode(code);
            return this;
        }

        public ResultJson data(String key, Object value) {
            this.data.put(key, value);
            return this;
        }

        public ResultJson data(Map<String, Object> map) {
            this.setData(map);
            return this;
        }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }

}
